package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.RscResultDetailDao;
import com.fdb.efp.nls.service.domain.RscResultDetail;
import com.fdb.efp.nls.service.facade.RscResultDetailService;
import com.fdb.efp.nls.service.vo.RscResultDetailVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>ServiceImpl: 风险分类结果明细表				<p>
 * @author chenqm1
 * @date 2018-05-07
 */
@Service("rscResultDetailService")
public class RscResultDetailServiceImpl implements RscResultDetailService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(RscResultDetailServiceImpl.class);

	@Autowired
	private RscResultDetailDao rscResultDetailDao;
	
	/**
	 * 新增操作
	 */
	public int insertRscResultDetail(RscResultDetailVO inRscResultDetailVo) {
		logger.debug("当前新增数据为:"+ inRscResultDetailVo.toString());
		int num = 0;
		try {
			RscResultDetail rscResultDetail = new RscResultDetail();
			beanCopy(inRscResultDetailVo, rscResultDetail);
			num = rscResultDetailDao.insertRscResultDetail(rscResultDetail);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(RscResultDetailVO inRscResultDetailVo) {
		logger.debug("当前删除数据条件为:"+ inRscResultDetailVo);
		int num = 0;
		try {
			RscResultDetail rscResultDetail = new RscResultDetail();
			beanCopy(inRscResultDetailVo, rscResultDetail);
			num = rscResultDetailDao.deleteByPk(rscResultDetail);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inRscResultDetailVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(RscResultDetailVO inRscResultDetailVo) {
		logger.debug("当前修改数据为:"+ inRscResultDetailVo.toString());
		int num = 0;
		try {
			RscResultDetail rscResultDetail = new RscResultDetail();
			beanCopy(inRscResultDetailVo, rscResultDetail);
			num = rscResultDetailDao.updateByPk(rscResultDetail);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inRscResultDetailVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public RscResultDetailVO queryByPk(RscResultDetailVO inRscResultDetailVo) {
		
		logger.debug("当前查询参数信息为:"+ inRscResultDetailVo);
		try {
			RscResultDetail queryRscResultDetail = new RscResultDetail();
			beanCopy(inRscResultDetailVo, queryRscResultDetail);
			RscResultDetail queryRslRscResultDetail = rscResultDetailDao.queryByPk(queryRscResultDetail);
			if (Objects.nonNull(queryRslRscResultDetail)) {
				RscResultDetailVO outRscResultDetailVo = beanCopy(queryRslRscResultDetail, new RscResultDetailVO());
				logger.debug("当前查询结果为:"+ outRscResultDetailVo.toString());
				return outRscResultDetailVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<RscResultDetailVO> queryAllOwner(RscResultDetailVO rscResultDetailVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<RscResultDetailVO> list = null;
		try {
			List<RscResultDetail> rscResultDetails = rscResultDetailDao.queryAllOwnerByPage(rscResultDetailVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ rscResultDetails.size());
			pageSet(rscResultDetails, rscResultDetailVo);
			list = (List<RscResultDetailVO>) beansCopy(rscResultDetails, RscResultDetailVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<RscResultDetailVO> queryAllCurrOrg(RscResultDetailVO rscResultDetailVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<RscResultDetail> rscResultDetails = rscResultDetailDao.queryAllCurrOrgByPage(rscResultDetailVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+rscResultDetails.size());
		List<RscResultDetailVO> list = null;
		try {
			pageSet(rscResultDetails, rscResultDetailVo);
			list = (List<RscResultDetailVO>) beansCopy(rscResultDetails, RscResultDetailVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<RscResultDetailVO> queryAllCurrDownOrg(RscResultDetailVO rscResultDetailVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<RscResultDetail> rscResultDetails = rscResultDetailDao.queryAllCurrDownOrgByPage(rscResultDetailVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ rscResultDetails.size());
		List<RscResultDetailVO> list = null;
		try {
			pageSet(rscResultDetails, rscResultDetailVo);
			list = (List<RscResultDetailVO>) beansCopy(rscResultDetails, RscResultDetailVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}

	@Override
	public RscResultDetailVO queryFirstByClaDate(RscResultDetailVO rscResultDetailVO) {
		
		logger.debug("当前查询参数信息为:"+ rscResultDetailVO);
		try {
			RscResultDetail queryRscResultDetail = new RscResultDetail();
			beanCopy(rscResultDetailVO, queryRscResultDetail);
			RscResultDetail queryRslRscResultDetail = rscResultDetailDao.queryFirstByClaDate(queryRscResultDetail);
			if (Objects.nonNull(queryRslRscResultDetail)) {
				RscResultDetailVO outRscResultDetailVo = beanCopy(queryRslRscResultDetail, new RscResultDetailVO());
				logger.debug("当前查询结果为:"+ outRscResultDetailVo.toString());
				return outRscResultDetailVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}
}
